/**
 * 角色权限
 */
const mongoose = require('mongoose')
const shortid = require('shortid')
const moment = require('moment')
const Menu = require('../menu/models_menu.js')
const Schema = mongoose.Schema

const RoleSchema = new Schema({
  // 数据库中存储ID
  _id: {
    type: String,
    default: shortid.generate
  },
  rolecode:String,// 编码
  rolename: String,    // 名称
  description: String,    // 描述
  menu:[
    {
      type: String,
      ref: 'Menu'
    }
  ],
  group:{
    type: String,
    default:''
  },  
  // 是否激活
  enable: {
    type: Boolean,
    default: true
  },
  create_time: {
    type: Date,
    default: Date.now
  }
})

RoleSchema.path('create_time').get(function (v) {
  return moment(v).utc().utcOffset(-8).format("YYYY-MM-DD")
})

module.exports = mongoose.model('Role', RoleSchema)